/**
 * Tokenizer.h
 *
 * @author Bematech S.A.
 */

#ifndef __BILBAO_UTIL_TOKENIZER_CLASS_H__
#define __BILBAO_UTIL_TOKENIZER_CLASS_H__

#include "bilbao/types.h"

// default delimiter string (space, tab, newline, carriage return, form feed)
//const std::string DEFAULT_DELIMITER = " \t\v\n\r\f";
const std::string DEFAULT_DELIMITER = "|";

namespace bilbao
{
	namespace util
	{
		class Tokenizer
		{
		public:
			/*
			 * Construtor padrão
			 */
			Tokenizer( void );

			/*
			 * Construtor
			 */
			Tokenizer( const String& str, const String& delimiter = DEFAULT_DELIMITER );

			/*
			 * Destrutor
			 */
			~Tokenizer( void );

			/*
			 * set string and delimiter
			 */
			void set( const String& str, const String& delimiter = DEFAULT_DELIMITER );

			/*
			 * set source string only
			 */
			void setString( const String& str );

			/*
			 * set delimiter string only
			 */
			void setDelimiter( const String& delimiter );

			/*
			 * return the next token, return "" if it ends
			 */
			String next( void );

			/*
			 * return array of tokens from current cursor
			 */
			Vector< String > split( void );

		private:
			/*
			 * ignore leading delimiters
			 */
			void skipDelimiter( void );

			/*
			 * check if the current char is delimiter
			 */
			bool isDelimiter( const char& c );

			/*
			 * input string
			 */
			String _buffer;

			/*
			 * output string
			 */
			String _token;

			/*
			 * delimiter string
			 */
			String _delimiter;

			/*
			 * string iterator pointing the current position
			 */
			String::const_iterator _currPos;

		};
	} // namespace util
} // namespace bilbao

#endif // __BILBAO_UTIL_TOKENIZER_CLASS_H__
